In WebObjects, applications that use the Enterprise Objects Framework must enlist the help of the EOEditingContext class to archive enterprise objects. The primary reason is so that EOEditingContext can keep track, from one database transaction to the next, of the objects it is designed to manage. But using an EOEditingContext for archiving also benefits your application in these other ways:
// WebScript exampleThe Java packages provide a different archiving mechanism; your Java classes should implement the java.io.Serializable interface. This interface consists of two methods: writeObject, which roughly corresponds to encodeWithCoder:; and readObject, which roughly corresponds to initWithCoder:.
- encodeWithCoder:(NSCoder *)aCoder {
[EOEditingContext encodeObject:self withCoder:aCoder];
}
- initWithCoder:(NSCoder *)aDecoder {
[EOEditingContext initObject:self withCoder:aDecoder];
return self;
}
// Java exampleThe enterprise object simply passes on responsibility for archiving and unarchiving itself to the EOEditingContext class, by invoking the encodeObject:withCoder: and initObject:withCoder: methods in WebScript or Objective-C (writeObject and readObject in Java) and passing a reference to itself (self or this) as one of the arguments. The editing context takes care of the rest. (See the EOEditingContext class specification in the Enterprise Objects Framework Reference for more information.)
private void writeObject(java.io.ObjectOutputStream out)
throws IOException {
EOEditingContext.writeObjectToStream(this, out);
}
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException{
EOEditingContext.initObjectFromStream(this, in);
}
Table of Contents
Next Section